package ServiceLayer;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;

import com.example.genericrpg_android.GameView;

public class Input {
	public static final int UP = 0;
	public static final int RIGHT = 1;
	public static final int DOWN = 2;
	public static final int LEFT = 3;
	public static final int A = 4;
	public static final int B = 5;
	public static final int PAUSE = 6;
	
	public Bitmap dPad;
	public Bitmap aButton;
	public Bitmap bButton;
	public Bitmap pauseButton; 
	
	private double zoom;
	private int gap;
	
	public Rect dPadSource, dPadDest, 
				aSource, aDest, 
				bSource, bDest, 
				pauseSource, pauseDest, 
				up, down, left, right, a, b, pause ;
    
    public Input(Context activity) {
    	try {
    		dPad = BitmapFactory.decodeStream(activity.getAssets().open("images/dPad.png"));
    		aButton = BitmapFactory.decodeStream(activity.getAssets().open("images/a.png"));
    		bButton = BitmapFactory.decodeStream(activity.getAssets().open("images/b.png"));
    		pauseButton = BitmapFactory.decodeStream(activity.getAssets().open("images/pause.png"));
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
    }
    
    public void initializeVariables(GameView view) {    
    	zoom = 1.2;
    	if (view.getWidth()< 500)
    		zoom =  0.8;
    	gap = (int)(30);
    	
    	dPadSource = new Rect(0, 0, dPad.getWidth(), dPad.getHeight());
    	dPadDest = new Rect(gap, view.getHeight() - (gap + (int)(dPad.getHeight() * (zoom * 1.5))), gap + (int)(dPad.getWidth() * (zoom * 1.5)), view.getHeight() - gap);
    	
    	aSource = new Rect(0, 0, aButton.getWidth(), aButton.getHeight());
    	aDest = new Rect((view.getWidth() - (gap / 2) - (int)(aButton.getWidth() * (zoom))), view.getHeight() - (gap + (int)(aButton.getHeight() * (zoom))), 
    			(view.getWidth() - (gap / 2)), view.getHeight() - gap);
    	
    	bSource = new Rect(0, 0, bButton.getWidth(), bButton.getHeight());
    	bDest = new Rect((view.getWidth() - (int)(gap * 0.75) - ((int)(bButton.getWidth() * (zoom)) * 2)), view.getHeight() - (gap + (int)(bButton.getHeight() * (zoom))), 
    			(view.getWidth() - (int)(gap * 0.75) - (int)(bButton.getHeight() * (zoom))), view.getHeight() - gap);
    	
    	pauseSource = new Rect(0, 0,pauseButton.getWidth(), pauseButton.getHeight());
    	pauseDest = new Rect((view.getWidth() - (gap / 3) - (int)(pauseButton.getWidth())), (gap / 3), 
    			(view.getWidth() - (gap / 3)), (int)(pauseButton.getHeight()) + (gap / 3));
    	
	    up = new Rect(dPadDest.left + (dPadDest.width() / 3), dPadDest.top, dPadDest.right - (dPadDest.width() / 3), dPadDest.top + (dPadDest.height() / 3));
	    down = new Rect(dPadDest.left + (dPadDest.width() / 3), dPadDest.bottom - (dPadDest.height() / 3), dPadDest.right - (dPadDest.width() / 3), dPadDest.bottom);
	    left = new Rect(dPadDest.left, dPadDest.top + (dPadDest.height() / 3), dPadDest.left + (dPadDest.width() / 3), dPadDest.bottom - (dPadDest.height() / 3));
	    right = new Rect(dPadDest.right - (dPadDest.width() / 3), dPadDest.top + (dPadDest.height() / 3), dPadDest.right, dPadDest.bottom - (dPadDest.height() / 3));
	    a = aDest;
	    b = bDest;
	    pause = pauseDest;
    }
}
